<?
  class message_model extends add_model_module{
   function returnForStandby(){    return $this->db->row_array($this->db->query("SELECT ns_doc.*,id_lang_text.* FROM ns_doc,id_lang_text,ns_tree WHERE ns_doc.children_id=id_lang_text.id AND id_lang_text.lang='".$_SESSION['lang']."' AND ns_tree.id=ns_doc.father_id AND(ns_tree.id=1 OR ns_tree.lft=0) AND ns_doc.module='message'"));
   }

     function returnSide(){
   	return $this->db->result_array($this->db->query("SELECT * From side_site WHERE id_template=( SELECT id From templates WHERE show_me='1')"));
   }

   function insert($class,$func,$father_id,$lang_arr,$lastInsertLangTextId){   	$this->db->query("START TRANSACTION;");
   	$lastInsertLangTextId++;
   	foreach($lang_arr as $key=>$value){    $this->db->query("INSERT INTO id_lang_text SET id=".$lastInsertLangTextId.",text='default message',lang='".$value['name']."',date=".date("y-m-d").";");
    }
    $this->db->query("INSERT INTO ns_doc SET children_id=".$lastInsertLangTextId.",show_me=1,father_id=".$father_id.",module='".$class."',side_for_doc='title',date=".date("y-m-d").";");
    $ns_docL=mysql_insert_id();
    $this->db->query("COMMIT");
    return $ns_docL;
   }

   function update($id,$data){   	$this->db->query("START TRANSACTION;");
   	//$last=$this->returnLastId("+");
   	$result=$this->get_info("children_id","ns_doc","id",$id);     foreach($data['text'] as $key=>$value){     $this->db->query("UPDATE  id_lang_text SET text='".$value."',date=".date("y-m-d")." WHERE id=".$result." AND lang='".$key."';");
     }
     $this->db->query("UPDATE ns_doc SET show_me=".$data['show_me'].",side_for_doc='".$data['sidedoc']."',children_id=".$result." WHERE id=".$id.";");


     $this->db->query("COMMIT");
    return;
   }


  }



?>